<script setup>
import { reactive, ref, onMounted } from "vue";
import { useRouter } from 'vue-router'
import { getNewSongs } from '../api/song'
import MusicItem from "../components/MusicItem.vue";

const router = useRouter();
const tags = reactive([
  {
    key: 0,
    name: '全部'
  },
  {
    key: 7,
    name: '华语'
  },
  {
    key: 96,
    name: '欧美'
  },
  {
    key: 8,
    name: '日本'
  },
  {
    key: 16,
    name: '韩国'
  }
])
const tagActive = ref(0)
const songs = ref([])

const switchActive = (key) => {
  tagActive.value = key
  getSongs()
}

const toPage = (path) => {
  router.push({path})
}

const getSongs = () => {
  getNewSongs(tagActive.value).then((res) => {
    songs.value = res.data
  })
}

onMounted(() => {
  getSongs()
})
</script>

<template>
  <div class="tags">
    <div class="tags-item">
      <span>新歌速递</span>
      <img class="tags-item-image animate__animated animate__rubberBand" src="../assets/yinfu.png" alt=""/>
    </div>
    <div class="tags-item" @click="toPage('/newDisc')">新碟上架</div>
  </div>
  <div class="tab-container">
    <div
      v-for="item in tags"
      :key="item.key"
      :class="`type-item ${item.key === tagActive ? 'tagActive' : ''}`"
      @click="switchActive(item.key)"
    >
      {{ item.name }}
    </div>
    <div class="b-warp">
      <div class="warp-btn">
        <span class="iconfont icon-bofang"></span>
        <span>播放全部</span>
      </div>
      <div class="warp-btn-doc">
        <span class="iconfont icon-tianjiagedan"></span>
        <span>收藏全部</span>
      </div>
    </div>
  </div>
  <div class="songs-list">
    <div class="song-item">
      <div class="song-num">序号</div>
      <div class="tr">标题</div>
      <div class="tr">专辑</div>
      <div class="song-num">喜欢</div>
      <div class="song-num">时长</div>
    </div>
    <div v-for="(item,index) in songs" :key="item.id">
      <music-item :item="item" :index="index + 1"/>
    </div>
  </div>
</template>

<style scoped lang="scss">
@mixin boxCenter {
  display: flex;
  justify-content: center;
  align-items: center;
}
.tags {
  width: 100%;
  color: #000000;
  display: flex;
  box-sizing: border-box;
  padding: 0 24px;
  //margin: 8px 0;
  .tags-item {
    font-size: 16px;
    letter-spacing: 1px;
    position: relative;
    cursor: pointer;
    &:nth-child(1) {
      margin-right: 24px;
      span {
        font-weight: bold;
      }
    }
  }
}
.tags-item-image {
  width: 20px;
  height: 26px;
  position: absolute;
  right: -14px;
  top: 6px;
}
.tab-container {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding: 0 24px;
  margin: 24px 0;
}
.type-item {
  min-width: 60px;
  height: 35px;
  color: #1b1b1f;
  font-size: 13px;
  letter-spacing: 1px;
  @include boxCenter;
  border: 1px solid #1b1b1f;
  border-radius: 50px;
  cursor: pointer;
  margin-right: 16px;
  &:hover {
    background: rgb(216.8, 235.6, 255);
    color: #1e90ff;
    border-color: #1e90ff;
  }
}

.tagActive {
  color: #fff;
  background: #1e90ff;
  border: none;
  &:hover {
    color: #fff;
    background: #1e90ff;
    border: none;
  }
}

.b-warp {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}
.warp-btn {
  min-width: 60px;
  height: 35px;
  font-size: 14px;
  background: #1e90ff;
  border-radius: 50px;
  padding: 0 14px;
  cursor: pointer;
  @include boxCenter;
  .iconfont {
    margin-right: 6px;
  }
}
.warp-btn-doc {
  min-width: 60px;
  height: 35px;
  font-size: 14px;
  color: #1e90ff;
  @include boxCenter;
  padding: 0 14px;
  margin-left: 12px;
  cursor: pointer;
  border-radius: 50px;
  border: 1px solid #1e90ff;
  .iconfont {
    font-size: 12px;
    margin-right: 6px;
  }
  &:hover {
    background: rgb(216.8, 235.6, 255);
    color: #1e90ff;
    border-color: #1e90ff;
  }
}

.songs-list {
  box-sizing: border-box;
  padding: 0 24px;
}
.song-item {
  height: 40px;
  color: #000000;
  display: flex;
  align-items: center;
}
.song-num {
  width: 50px;
  font-size: 12px;
  letter-spacing: 1px;
  color: #515c67;
  @include boxCenter;
}
.tr {
  flex: 1;
  font-size: 12px;
  letter-spacing: 1px;
  color: #515c67;
  display: flex;
  justify-content: flex-start;
}
</style>
